﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Pikapika
{
    public static class MiscExtensions
    {
        public static DateTimeOffset CorrectTimeZone(this DateTime value)
        {
            return new DateTimeOffset(value, TimeSpan.Zero).ToOffset(Properties.Settings.Default.TimeZone);
        }

        public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
        {
            return GetValueOrDefault<TKey, TValue>(dict, key, (TValue)default (TValue));
        }

        public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue)
        {
            TValue ret;
            if (dict.TryGetValue(key, out ret))
            {
                return ret;
            }
            return defaultValue;
        }
    }
}